<div class="storeProducts form">
<?php //echo $this->Form->create('StoreProduct',array('url'=>array('plugin'=>'store','controller'=>'products','action'=>'edit'),'type' => 'file'));?>
<?php
echo $javascript->link('ckeditor/ckeditor');
echo $cksource->create(__("StoreProduct",true),array('url'=>array('plugin'=>'store','controller'=>'products','action'=>'edit'),'type' => 'file')); 
?>
<?php 
//$config['toolbar'] = array( 
//    array( 'Bold', 'Italic', 'Underline', 'Strike' ), 
//    array( 'Image', 'Link', 'Unlink', 'Anchor' ) 
//); 
$config['height'] = 800;
?>

<?php
echo $javascript->codeBlock("	
	$(document).ready(function(){
		// click chackbox events
 		$( '#selectAllTypes').unbind('click').bind('click', function(){
 			if($(this).attr('checked')){
				$('.selectedTypes').attr('checked',true);
				$('.selectedTypes').attr('value',1);
			}else{
				$('.selectedTypes').attr('checked',false);
				$('.selectedTypes').attr('value',0);
			}
		});
		
		$( '#inputAllInventory').unbind('keyup').bind('keyup', function(){
				$('.selectedInventory').attr('value',$(this).attr('value'));
		});
	});	
",$options = array('allowCache'=>false,'safe'=>false,'inline'=>false));
?>

	<fieldset>
 		<legend><?php __d('store','Edit Store Product'); ?></legend>
		<table width="100%" cellpadding="10" cellspacing="0">
				<tr>
					<td width="40%" valign="top">
					<?php
						echo $this->Form->hidden('id');
						echo $this->Form->hidden('upload_id');
						
						echo $this->Form->input('name',array('class'=>'_100','error' => array('notEmpty' => __('This field cannot be left blank', true) )));
						echo $this->Form->input('serial_number',array('class'=>'_50'));
						
						echo $this->Form->input('price_detaliczna',array(array('label'=>__d('store','Price',true)),'after'=>$this->data['StoreProduct']['currency_id']));
//						echo $this->Form->input('price_przecena',array('after'=>$this->data['StoreProduct']['currency_id']));
						echo $this->Form->input('price_promocja',array(array('label'=>__d('store','Price - Special Offer',true)),'after'=>$this->data['StoreProduct']['currency_id']));
						echo $this->Form->input('currency_id',array('options'=>$storeCurrencies));
						echo $this->Form->input('www',array('class'=>'_100'));	
//						echo $this->Form->input('tax_id',array('options'=>$storeTaxes,'empty'=>''));
//						echo $this->Form->input('unit_id',array('options'=>$storeUnits,'empty'=>''));
						echo $this->Form->input('active');
					?>
					</td>
					<td width="30%" valign="top">
					<?php 
						echo $this->Form->input('group_id',array('label'=>__d('store','Homepage Display',true),'options'=>$storeGroups,'empty'=>''));	
						$category_id = (isset($this->data['StoreCategory'][0]['id'])) ? $this->data['StoreCategory'][0]['id'] : null;
						
						if(isset($this->data['StoreCategory'][0]['StoreProductCategory']['id'])){
							echo $this->Form->hidden('StoreProductCategory.id',array('value'=>$this->data['StoreCategory'][0]['StoreProductCategory']['id']));
							echo $this->Form->hidden('StoreProductCategory.old_category_id',array('value'=>$category_id));
						}						
					?>
					<?php							
						echo $this->Form->input('StoreUpload.0.file', array('type' => 'file'));
						echo $fileUpload->image($this->data['StoreUpload']['name'],array('autoResize'=>true,'width'=>150,'imagePathOnly'=>false));
					?>						
					</td>
					<td width="30%" valign="top" rowspan="3">

						<?php 
							echo $this->Form->input('StoreProductCategory.category_id',array('options'=>$parentCategories,'selected'=>$category_id,'class'=>'_100'));
							$this->Js->get('#StoreProductCategoryCategoryId')->event('change', $this->Js->request( 
								array('plugin'=>'store','controller'=>'products','action'=>'product_types'),
								array( 
									'dataExpression' => true,
									'update'=>'#selectProductTypes',
									'data'=>'{category_id:$(\'#StoreProductCategoryCategoryId\').val()}',
									'before'=>'$(\'#selectProductTypes\').html("<tr><td>'.__d('store','reading data, please wait ...',true).'</td></tr>")',
								))									
							);
						?>
						<div id="selectProductTypes">
							<?php 	
								echo $this->Form->input('StoreModel.StoreModel',array('label'=>__d('store','Offer Type',true),'options'=>$storeModels,'empty'=>'','class'=>'_100'));						
								$types = array();								
								if(isset($this->data['StoreType']) && is_array($this->data['StoreType'])){
									foreach ($this->data['StoreType'] as $type) {
										$types[$type['id']]['inventory']=$type['StoreProductType']['inventory'];
										$types[$type['id']]['for_group']=$type['StoreProductType']['for_group'];
									}
								}
								//echo $this->Form->input('type_id',array('options'=>$storeTypes,'selected'=>$selected,'multiple'=>true, 'style'=>'height:200px;'));
							
							?>
							
							<table class="index" id="selectProductTypes">
								<tr>
									<th>
										<input type="checkbox" id="selectAllTypes">
									</th>
									<th>
										<?php echo __d("store","Name",true)?>
									</th>
									<th>
										<div class="input text"><input type="text" size="2" id="inputAllInventory"></div>
									</th>
									<th>
										<?php echo __d("store","For",true)?>
									</th>
								</tr>	
								
								<tr>
									<td valign="middle" align="center">								
										<?php echo $this->Form->checkbox("StoreProduct.service", array('label'=>false,'after'=>false  ));?>
									</td>
									<td valign="middle" colspan="3">
										<?php echo __('Serice',true)?>
									</td>
								
								</tr>
												
								<?php 
								$i = 0;
								foreach ($storeTypes as $type_id => $name) { 
									$class = null;
									if ($i++ % 2 == 0) {
										$class = ' class="altrow"';
									}
		
									$selected = (array_key_exists($type_id, $types)) ? 'checked' : false;
									$inventory = (array_key_exists($type_id, $types)) ? $types[$type_id]['inventory'] : 0;
									$for_group = (array_key_exists($type_id, $types)) ? $types[$type_id]['for_group'] : null;
								?>
		
								<tr <?php echo $class;?>>
									<td valign="middle" align="center">								
										<?php echo $this->Form->checkbox("StoreType.type_id.{$type_id}", array('label'=>false,'after'=>false,'checked'=>$selected,'class'=>'selectedTypes' ));?>
									</td>
									<td valign="middle">
										<?php echo $name?>
									</td>
									<td valign="middle">
										<?php echo $this->Form->input("StoreType.inventory.{$type_id}",array('label'=>false,'size'=>2, 'value'=>$inventory,'class'=>'selectedInventory'));?>
									</td>
									<td valign="middle" class="last">
										<?php echo $this->Form->input("StoreType.for_group.{$type_id}",array('label'=>false,'options'=>$storeTypeGroup,'empty'=>'','selected'=>$for_group,'hiddenField'=>false,'style'=>'width: 110px;'))?>
									</td>									
								</tr>
								<?php }?>
							</table>
						</div>					
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php echo $cksource->ckeditor('content', array( 'config'=>$config));?>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<?php echo $this->Form->input('keywords',array('class'=>'_100'));?>
					</td>
				</tr>
			</table>
	
	</fieldset>
<?php echo $this->Form->end(__d('store','Submit', true));?>
</div>

<div class="storeProducts form">
	<h2 class="_50 float-left"><?php __d('store','Matching Jewellery');?></h2>	
	<?php echo $this->Html->link('+ add match',array('plugin'=>'store','controller'=>'products','action'=>'add_match',$this->data['StoreProduct']['id']),array('class'=>'float-right'))?>
	<table class="index" cellpadding="0" cellspacing="0">
	<tr>
			<th>&nbsp;</th>
			<th><?php __d('store','Offer Type');?></th>
			<th><?php __d('store','Category');?></th>
			<th><?php __d('store','Name');?></th>
			<th><?php __d('store','Price');?></th>
			<?php if($session->check('Auth.User.id')){?><th class="actions"><?php __d('store','Actions');?></th><?php }?>
	</tr>
	<?php
	$i = 0;
	foreach ($storeMatchProducts as $storeProduct):
		$class = null;
		if ($i++ % 2 == 0) {
			$class = ' class="altrow"';
		}
	?>
	<tr<?php echo $class;?>>
		<td valign="middle" align="left">
			<?php echo $this->Html->link($fileUpload->image($storeProduct['StoreProduct']['StoreUpload']['name'],array('autoResize'=>true,'width'=>100,'imagePathOnly'=>false))
				, array('action' => 'view', $storeProduct['StoreProduct']['id']),array('escape'=>false)); ?>&nbsp;
		</td>
		<td valign="top" align="left">
			<?php 
				if(isset($storeProduct['StoreProduct']['StoreModel']) && is_array($storeProduct['StoreProduct']['StoreModel'])){
					foreach ($storeProduct['StoreProduct']['StoreModel'] as $key_model => $model) {
						echo $model['name'].'<br/>';
					}
				}
			?>&nbsp;
		</td>		
		<td align="left" valign="top">
			<?php 
				if(is_array($storeProduct['StoreProduct']['StoreCategory']) && !empty($storeProduct['StoreProduct']['StoreCategory'])){
					foreach ($storeProduct['StoreProduct']['StoreCategory'] as $cat_key => $category) {
						echo $category['name'].'<br/>';
					}
				}
			?>
		&nbsp;</td>		
		<td align="left" valign="top" ><?php echo $storeProduct['StoreProduct']['name']; ?>&nbsp;</td>
		<td align="right">
			<?php if($storeProduct['StoreProduct']['price_przecena'] > 0 && $storeProduct['StoreProduct']['price_promocja'] == 0){?>
					<span class="product-view-price-discount"><?php echo $this->Store->price($storeProduct['StoreProduct']['price_detaliczna'],2,'','',$storeProduct['StoreProduct']['currency_id'],$storeProduct['StoreProduct']['StoreCurrency']['exchange'] );?></span> 
					<span class="product-view-price"><?php echo $this->Store->price($storeProduct['StoreProduct']['price_przecena'],2,'',null,$storeProduct['StoreProduct']['currency_id'],$storeProduct['StoreProduct']['StoreCurrency']['exchange'])?></span> 							 
			<?php }else if( $storeProduct['StoreProduct']['price_promocja'] > 0){?>
					<span class="product-view-price-discount"><?php echo $this->Store->price($storeProduct['StoreProduct']['price_detaliczna'],2,'','',$storeProduct['StoreProduct']['currency_id'],$storeProduct['StoreProduct']['StoreCurrency']['exchange']);?></span> 
					<span class="product-view-price"><?php echo $this->Store->price($storeProduct['StoreProduct']['price_promocja'],2,'',null,$storeProduct['StoreProduct']['currency_id'],$storeProduct['StoreProduct']['StoreCurrency']['exchange'])?></span> 							
			<?php }else{?>
					<span class="product-view-price"><?php echo $this->Store->price($storeProduct['StoreProduct']['price_detaliczna'],2,'',null,$storeProduct['StoreProduct']['currency_id'],$storeProduct['StoreProduct']['StoreCurrency']['exchange'])?></span>
			<?php }?>					
		</td>
		<td class="actions" align="center" valign="middle">
			<?php echo $this->Html->link($html->image('firma/actions_16_delete.png',array('title'=>__d("store","View",true))), array('plugin'=>'store','controller'=>'products','action'=>'delete_match',$this->data['StoreProduct']['id'], $storeProduct['StoreProduct']['id']), array('escape'=>false), sprintf(__d('store','Are you sure you want to delete # %s?', true), $storeProduct['StoreProduct']['name'])); ?>
		</td>
	</tr>
<?php endforeach; ?>
	</table>

</div>		

<?php if($session->check('Auth.User.id')){?>
<?php echo $this->element('toolbar_actions_main',array('plugin'=>'store','toolbar'=>'product'))?>
<?php }?>

